from urllib import request
import json


# 查看交换机的流量统计信息
def get_switch_countinfo(dpid):
    url = 'http://localhost:8080/stats/aggregateflow/{}'.format(dpid)
    # url = 'http://localhost:5000/test/{}'.format(dpid)
    res = request.Request(url)
    res_data = request.urlopen(res)
    res_data = json.loads(res_data.read())

    packet_count = res_data[str(dpid)][0]['packet_count']
    byte_count = res_data[str(dpid)][0]['byte_count']
    flow_count = res_data[str(dpid)][0]['flow_count']

    return packet_count, byte_count, flow_count

